package com.egao.orderB.service.impl;

import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.JsonResult;
import com.egao.common.system.entity.User;
import com.egao.orderB.biz.OceanPreStoragePositionBiz;
import com.egao.orderB.biz.OtherFeeBiz;
import com.egao.orderB.entity.OceanPreStoragePosition;
import com.egao.orderB.entity.OtherFee;
import com.egao.orderB.service.OceanPreStoragePositionService;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

//import com.egao.orderB.mapper.OceanPreStoragePositionMapper;
//import javax.transaction.Transactional;

/**
 * 预存仓位服务实现类
 * @author : Doman
 * @date : 2021-10-19 16:47:57
 * @version ：1.0
 */
@Service
public class OceanPreStoragePositionServiceImpl /*extends ServiceImpl<OceanPreStoragePositionMapper, OceanPreStoragePosition> */implements OceanPreStoragePositionService {

	@Autowired
	private OceanPreStoragePositionBiz oceanPreStoragePositionBiz;
	@Autowired
	private OtherFeeBiz otherFeeBiz;

  @Override
  public JsonResult list(PageResult2<T> page, OceanPreStoragePosition oceanPreStoragePosition, User loginUser)  throws Exception{
    return oceanPreStoragePositionBiz.list(page,oceanPreStoragePosition,loginUser);
  }

  @Override
  public JsonResult list(OceanPreStoragePosition oceanPreStoragePosition, User loginUser) {
    return JsonResult.ok().setData(oceanPreStoragePositionBiz.list(oceanPreStoragePosition,loginUser));
  }

  @Override
  public JsonResult listOpen(OceanPreStoragePosition oceanPreStoragePosition, User loginUser) {
//    OceanPreStoragePosition oceanPreStoragePosition2 = oceanPreStoragePositionBiz.getById(oceanPreStoragePosition);
    OtherFee otherFee = new OtherFee();
    otherFee.setTableId(oceanPreStoragePosition.getId());
    otherFee.setTableName("chf_ocean_pre_storage_position");
    oceanPreStoragePosition.setOtherFeeList(otherFeeBiz.list(otherFee, loginUser));
    return JsonResult.ok().put("data", oceanPreStoragePosition);
  }

  @Override
  public JsonResult boxTypeNum(OceanPreStoragePosition oceanPreStoragePosition, User loginUser) {
    return JsonResult.ok().setData(oceanPreStoragePositionBiz.boxTypeNum(oceanPreStoragePosition,loginUser));
  }

  @Override
  public JsonResult getById(OceanPreStoragePosition oceanPreStoragePosition) {
    return JsonResult.ok().setData(oceanPreStoragePositionBiz.getById(oceanPreStoragePosition));
  }

  @Transactional
  @Override
  public JsonResult save(OceanPreStoragePosition oceanPreStoragePosition, User loginUser) {
    if (oceanPreStoragePositionBiz.save(oceanPreStoragePosition, loginUser)) {
      return JsonResult.ok("添加成功");
    }
    return JsonResult.error("添加失败");
  }

  @Transactional
  @Override
  public JsonResult update(OceanPreStoragePosition oceanPreStoragePosition, User loginUser) {
    if (oceanPreStoragePositionBiz.update(oceanPreStoragePosition, loginUser)) {
      return JsonResult.ok("修改成功");
    }
    return JsonResult.error("修改失败");
  }

  @Transactional
  @Override
  public JsonResult cancel(OceanPreStoragePosition oceanPreStoragePosition, User loginUser) {
    if (oceanPreStoragePositionBiz.cancel(oceanPreStoragePosition, loginUser)) {
      return JsonResult.ok("取消预存仓位成功");
    }
    return JsonResult.error("取消预存仓位失败");
  }

  @Transactional
  @Override
  public JsonResult remove(OceanPreStoragePosition oceanPreStoragePosition, User loginUser) {
    if (oceanPreStoragePositionBiz.remove(oceanPreStoragePosition, loginUser)) {
      return JsonResult.ok("删除成功");
    }
    return JsonResult.error("删除失败");
  }

}
